package cn.green.core.excel;

import com.alibaba.fastjson.JSONArray;
import cn.green.core.model.QTable;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import java.io.InputStream;
import java.io.OutputStream;

/**
 * 动态表excel组件
 */
public interface QExcel {

    String EXCEL_2003 = "xls";
    String EXCEL_2007 = "xlsx";
    int MAX_ROW_ELS = 65535;
    int MAX_ROW_XLSX = Integer.MAX_VALUE;

    HSSFCellStyle xlsTitleStyle(HSSFWorkbook workbook);

    XSSFCellStyle xlsxTitleStyle(XSSFWorkbook workbook);

    HSSFCellStyle xlsValueStyle(HSSFWorkbook workbook);

    XSSFCellStyle xlsxValueStyle(XSSFWorkbook workbook);

    HSSFCellStyle xlsErrTitleStyle(HSSFWorkbook workbook);

    XSSFCellStyle xlsxErrTitleStyle(XSSFWorkbook workbook);

    HSSFCellStyle xlsErrorMsgStyle(HSSFWorkbook workbook);

    XSSFCellStyle xlsxErrorMsgStyle(XSSFWorkbook workbook);

    /**
     * 导入模板xls
     * @param table
     * @param outputStream
     */
    void templateXls(QTable table, OutputStream outputStream);

    /**
     * 导出xls文件
     * @param data
     * @param table
     * @param outputStream
     */
    void exportXls(JSONArray data, QTable table, OutputStream outputStream);

    /**
     * 导入xls文件
     * @param table
     * @param inputStream
     * @return
     */
    JSONArray importXls(QTable table, InputStream inputStream);

    /**
     * 生成错误xls文件
     * @param errorData
     * @param table
     */
    HSSFWorkbook generateErrorXls(JSONArray errorData, QTable table, String errorMsgColumnName);

    /**
     * 导入模板xlsx
     * @param table
     * @param outputStream
     */
    void templateXlsx(QTable table, OutputStream outputStream);

    /**
     * 导出xlsx文件
     * @param data
     * @param table
     * @param outputStream
     */
    void exportXlsx(JSONArray data, QTable table, OutputStream outputStream);

    /**
     * 导入xlsx文件
     * @param table
     * @param inputStream
     * @return
     */
    JSONArray importXlsx(QTable table, InputStream inputStream);

    /**
     * 生成错误xlsx文件
     * @param errorData
     * @param table
     */
    XSSFWorkbook generateErrorXlsx(JSONArray errorData, QTable table, String errorMsgColumnName);

}
